﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using System.Collections;

namespace Presentation
{
    public partial class AutoKeys : Form
    {
        public AutoKeys()
        {
            InitializeComponent();
            _LastMenu = ucmAbout;
            this.TransparencyKey = ((Bitmap)this.BackgroundImage).GetPixel(0, 0);
        }

        private void AutoKeys_Load(object sender, EventArgs e)
        {
            ucmAbout.Click+=new EventHandler(Menu_Click);
            ucmOption.Click += new EventHandler(Menu_Click);
            ucmListKey.Click += new EventHandler(Menu_Click);
            _Runing = new CRunning(this.Handle);
            _Runing.Start();
        }

        private UsecontrolMenu _LastMenu;
        private CRunning _Runing;

        private void Menu_Click(object sender, EventArgs e)
        {
            if (_LastMenu != (UsecontrolMenu)sender)
            {
                _LastMenu.DaNhan = false;
                _LastMenu = (UsecontrolMenu)sender;
                _LastMenu.DaNhan = true;
                ucAbout.Visible = ucmAbout.DaNhan;
                if (ucListKey.Visible != ucmListKey.DaNhan && ucListKey.Visible == false)
                {
                    ucListKey.HienThiDSKey();
                }
                ucListKey.Visible = ucmListKey.DaNhan;
                ucOption.Visible = ucmOption.DaNhan;
            }
        }

        private void niMain_MouseClick(object sender, MouseEventArgs e)
        {
            //if (e.Button == MouseButtons.Right)
            //{
            //    cmsIcon.Show(new Point(e.Location.X - cmsIcon.Width, e.Location.Y - cmsIcon.Height));
            //}
        }

        private void ucClose_MouseClick(object sender, MouseEventArgs e)
        {
            if(e.Button == MouseButtons.Left)
            {
                    Application.Exit();
            }
        }

        private void userControlButton1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                niMain.Visible = true;
                this.WindowState = FormWindowState.Minimized;
                this.ShowInTaskbar = false;
            }
        }

        private void niMain_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.WindowState = FormWindowState.Normal;
                this.ShowInTaskbar = true;
                niMain.Visible = false;
            }
        }

        private Boolean _Move = false;
        private Point _ToaDo;
        private void plMove_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _Move = true;
                _ToaDo = new Point(e.X, e.Y);
            }
        }

        private void plMove_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _Move = false;
                this.Location = new Point(this.Location.X + (e.X - _ToaDo.X), this.Location.Y + (e.Y - _ToaDo.Y));
            }
        }

        private void plMove_MouseMove(object sender, MouseEventArgs e)
        {
            if (_Move)
            {
                this.Location = new Point(this.Location.X + (e.X - _ToaDo.X), this.Location.Y + (e.Y - _ToaDo.Y));
            }
        }

        private void userControlButton2_MouseClick(object sender, MouseEventArgs e)
        {

            if (e.Button == MouseButtons.Left)
            {
                this.WindowState = FormWindowState.Minimized;
            }
        }

        private void AutoKeys_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("Are you sure want to quit?", "Auto Keys", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                e.Cancel = true;
        }

        private void AutoKeys_FormClosed(object sender, FormClosedEventArgs e)
        {
            _Runing.Disable();
        }
    }
}
